<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="120px" v-show="showSearch">
      <el-form-item label="地震事件名称" prop="eventName">
        <el-input v-model="queryParams.eventName" placeholder="请输入地震事件名称" clearable />
      </el-form-item>
      <el-form-item label="震级" prop="magnitude">
        <el-input v-model="queryParams.magnitude" placeholder="请输入震级" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" @click="handleAdd">新建</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" stripe>
      <el-table-column label="序号" align="center" width="55">
        <template #default="scope">
          <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="地震事件编号" align="center" prop="eventCode" width="200">
        <template #default="scope">
          <span style="color: #107ce1;cursor: pointer;" @click="handleEdit(scope.row)">{{ scope.row.eventCode }}</span>
        </template>
      </el-table-column>
      <el-table-column label="地震事件名称" align="center" prop="eventName"  width="200" show-overflow-tooltip />
      <el-table-column label="震级" align="center" prop="magnitude" width="80" />
      <el-table-column label="参考位置" align="center" prop="epicentralSite" />
      <el-table-column label="发震时刻" align="center" prop="eventTime" width="160" />
      <el-table-column label="事件状态" align="center" prop="eventStatus">
        <template #default="scope">
          <span v-if="scope.row.eventStatus == '0'">进行中</span>
          <span v-if="scope.row.eventStatus == '1'">结束</span>
          <span v-if="scope.row.eventStatus == '2'">已转换</span>
        </template>
      </el-table-column>
      <el-table-column label="创建单位" align="center" prop="createUnit" show-overflow-tooltip />
      <el-table-column label="创建人" align="center" prop="createUserName" show-overflow-tooltip />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template #default="scope">
          <el-button type="text" @click="handleSet(scope.row)" v-if="scope.row.isCurrentEvent == '0'">设为当前事件</el-button>
          <el-button type="text" v-if="scope.row.isCurrentEvent == '1'">已设为当前事件</el-button>
          <el-button type="text" @click="handleTransformation(scope.row)" v-if="scope.row.eventStatus == '0'">转换</el-button>
          <el-button type="text" @click="handleDelete(scope.row)" v-if="scope.row.eventStatus != '1'">删除</el-button>
          <el-button type="text" @click="handleEnd(scope.row)" v-if="scope.row.eventStatus != '1'">结束</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
      @pagination="getList" />

    <el-dialog :title="title1" v-model="simulatingEarthquakeBool" width="700px" append-to-body>
      <el-form ref="simulatingEarthquake" label-width="120px" :model="querySimulatingEarthquake" :rules="rulesSimulatingEarthquake">
        <el-row style="margin: 10px 0;">
          <el-col :span="10">
            <el-form-item label="省" prop="province">
              <el-select v-model="querySimulatingEarthquake.province" placeholder="请选择" @change="chooseFormProvince" style="width: 100%;">
                <el-option v-for="item in provinceFormData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="市" prop="city">
              <el-select v-model="querySimulatingEarthquake.city" placeholder="请选择" @change="chooseFormCity" style="width: 100%;">
                <el-option v-for="item in cityFormData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 10px 0;">
          <el-col :span="10">
            <el-form-item label="县" prop="district">
              <el-select v-model="querySimulatingEarthquake.district" placeholder="请选择" @change="chooseFormDistrict" style="width: 100%;">
                <el-option v-for="item in areaFormData" :key="item.id" :label="item.name" :value="item">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="乡镇" prop="town">
              <el-input v-model="querySimulatingEarthquake.town" placeholder="请输入乡镇" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 10px 0;">
          <el-col :span="10">
            <el-form-item label="震中经度" prop="longitude">
              <el-input v-model="querySimulatingEarthquake.longitude" placeholder="请输入震中经度" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="震中纬度" prop="latitude">
              <el-input v-model="querySimulatingEarthquake.latitude" placeholder="请输入震中纬度" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 10px 0;">
          <el-col :span="10">
            <el-form-item label="震级" prop="magnitude">
              <el-input v-model="querySimulatingEarthquake.magnitude" placeholder="请输入震级" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="地震时刻" prop="time">
              <el-date-picker
                v-model="querySimulatingEarthquake.time"
                type="datetime"
                value-format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择地震时刻"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 10px 0;">
          <el-col :span="10">
            <el-form-item label="震源深度(千米)" prop="depth">
              <el-input v-model="querySimulatingEarthquake.depth" placeholder="请输入震源深度" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="地震名称" prop="eventAbbrevia">
              <el-input v-model="querySimulatingEarthquake.eventAbbrevia" placeholder="请输入名称" clearable />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin: 10px 0;">
          <el-col :span="20">
            <el-form-item label="参考位置" prop="location">
              <el-input v-model="querySimulatingEarthquake.location" placeholder="请输入参考位置" clearable style="width: 500px" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="saveSimulatingEarthquake">保 存</el-button>
          <el-button @click="simulatingEarthquakeBool = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <el-dialog title="地震事件管理" v-model="open" width="850px" append-to-body>
      <el-button type="primary" @click="addSimulatingEarthquake" style="margin-top: 20px;">增加模拟地震</el-button>
      <el-form ref="sjglRef" label-width="120px" :model="queryParamsForm">
        <el-row style="margin: 20px 0;">
          <el-col :span="10">
            <el-form-item label="地震类型" prop="magnitude" label-width="80px">
              <el-select v-model="queryParamsForm.dataSource" class="m-2" placeholder="请选择" clearable>
                <el-option value="0" label="正式"></el-option>
                <el-option value="1" label="模拟"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="震级" prop="magnitude" label-width="60px">
              <el-input v-model="queryParamsForm.magnitude" placeholder="请输入震级" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary" @click="handleQuery1" style="float: right;">查询</el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loading1" ref="singleTableRef" :data="dataList1" stripe>
          <el-table-column label="单选" width="55px">
            <template #default="scope">
              <el-radio :label="scope.row.jscId" v-model="selectRadio"
                @click.native.stop.prevent="getCurrentRow(scope.row)">&nbsp;</el-radio>
            </template>
          </el-table-column>
          <el-table-column label="序号" align="center" type="index" width="55" />
          <el-table-column label="震级" align="center" prop="magnitude" />
          <el-table-column label="发震时刻" align="center" prop="fzTime" />
          <el-table-column label="类型" align="center" prop="createOrNot" >
            <template #default="scope">
              <span  v-if="scope.row.dataSource==0" >正式</span>
              <span  v-if="scope.row.dataSource==1" >模拟</span>
            </template>
          </el-table-column>
          <el-table-column label="经度" align="center" prop="longitude" />
          <el-table-column label="纬度" align="center" prop="latitude" />
          <el-table-column label="参考位置" align="center" prop="location" />
          <el-table-column label="是否创建地震事件" align="center" prop="createOrNot" >
            <template #default="scope">
              <span  v-if="scope.row.createOrNot==0" >已创建</span>
              <span  v-if="scope.row.createOrNot==1" >未创建</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" >
            <template #default="scope">
              <el-button v-if="scope.row.dataSource=='1'" type="text" @click="updateSimulatingEarthquake(scope.row)">修改</el-button>
              <el-button v-if="scope.row.dataSource=='1'" type="text" @click="deleteSimulatingEarthquake(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total1 > 0" :total="total1" v-model:page="queryParamsForm.page"
          v-model:limit="queryParamsForm.rows" @pagination="getList1" />
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="lower" :disabled="!selectRadio">下一步</el-button>
          <el-button @click="open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog :title="title" v-model="openAdd" width="600px" append-to-body>
      <el-form ref="addRef" label-width="120px" :rules="rules" :model="form">
        <el-row style="margin: 20px 0;">
          <el-col>
            <el-form-item label="地震事件编号" prop="eventCode" required>
              <el-input v-model="form.eventCode" placeholder="请输入地震事件编号" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="地震事件名称" prop="eventName">
              <el-input v-model="form.eventName" placeholder="请输入地震事件名称" clearable />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="震级" prop="magnitude" required>
              <el-input v-model="form.magnitude" placeholder="请输入震级" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="发震时刻" prop="eventTime" required>
              <el-input v-model="form.eventTime" placeholder="请输入发震时刻" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="参考位置" prop="epicentralSite" required>
              <el-input v-model="form.epicentralSite" placeholder="请输入参考位置" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="经度" prop="longitude" required>
              <el-input v-model="form.longitude" placeholder="请输入经度" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="纬度" prop="latitude" required>
              <el-input v-model="form.latitude" placeholder="请输入纬度" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="创建人单位" prop="createUnit" required>
              <el-input v-model="form.createUnit" placeholder="请输入创建人单位" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="创建人" prop="createUserName" required>
              <el-input v-model="form.createUserName" placeholder="请输入创建人" disabled />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="创建时间" prop="createTime" required>
              <el-input v-model="form.createTime" placeholder="请输入创建时间" disabled />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="upper" v-if="title == '新建地震事件'">上一步</el-button>
          <el-button type="primary" @click="save">保 存</el-button>
          <el-button @click="openAdd = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="seismicEvents">
import useEventStore from "@/store/modules/event";

import { getAllList, getAllList1, getDataName, saveData, getDetail, updateDate, setCurrentEvent,
 del, convert, simEarSave, simEarUpdate, simEarDelete,endSeismicEventCheck,endSeismicEvent } from "@/api/comprehensiveInformation/seismicEvents.js"
import { getProvince, getChildArea, getDivisionCode } from "@/api/system/division";
import { getDetail as getDetailAll, updateLoss } from "@/api/directLossAssess/lossRatio.js";
const { proxy } = getCurrentInstance();
const eventStore = useEventStore();
const currentEvent = computed(() => useEventStore().currentEvent);
const dataList = ref([]);
const dataList1 = ref([]);
const ids = ref();
const loading = ref(false);
const loading1 = ref(false);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const total1 = ref(0);
const showSearch = ref(true);
const open = ref(false);
const openAdd = ref(false);
const title = ref();
const selectionData = ref({});
const selectRadio = ref('');
const forbidden = ref(true);
const provinceFormData = ref([]);//表单省 
const cityFormData = ref([]);//表单市
const areaFormData = ref([]);//表单区、县
const isNew = ref(true); // true代表新建，false 代表转换
let m_curRow = null;
// 保留两位小数
const positive6decimals = (rule, value, callback) => {
	value = String(value)
	if (isNaN(value)|| !value) {
    return callback(new Error());
  }
  var re = /^([0-9]+[\d]*(.[0-9]{2}))$/;
  if (!re.test(value)) {
    callback(new Error());
  }else{
    callback();
  }
}
const data = reactive({
  queryParams: {
    page: 1,
    rows: 10,
    eventName: undefined,
    magnitude: undefined,
  },
  queryParamsForm: {
    page: 1,
    rows: 10,
    magnitude: undefined,
    dataSource: '0',
  },
  querySimulatingEarthquake: {
    province: '',
    city: '',
    district: '',
    town: '',
    location: '',
    eventAbbrevia: '',
    longitude: '',
    latitude: '',
    magnitude: '',
    depth: '',
    time: '',
    occurrenceDate: '',
    occurrenceTime: ''
  },
  form: {
  },
  formQuery: {

  },
  rules: {
    eventName: [{ required: true, message: "地震事件名称不能为空", trigger: "blur" }],
  },
  rulesSimulatingEarthquake: {
    province: [{ required: true, message: "省不能为空", trigger: "blur" }],
    city: [{ required: true, message: "市不能为空", trigger: "blur" }],
    district: [{ required: true, message: "县不能为空", trigger: "blur" }],
    location: [{ required: true, message: "参考位置不能为空", trigger: "blur" }],
    eventAbbrevia: [{ required: true, message: "地震名称不能为空", trigger: "blur" }],
    time: [{ required: true, message: "地震时刻不能为空", trigger: "blur" }],
    longitude:[{ required: true, message: "保留两位小数", trigger: "blur", validator: positive6decimals }],
    latitude:[{ required: true, message: "保留两位小数", trigger: "blur", validator: positive6decimals }],
    magnitude: [{ required: true, message: "震级不能为空", trigger: "blur" }],
    depth: [{ required: true, message: "震源深度不能为空", trigger: "blur" }],
  }
})
const { queryParams,formQuery, queryParamsForm, querySimulatingEarthquake, form, rules, rulesSimulatingEarthquake } = toRefs(data)

/** 获取省列表 */
function getProvinceData() {
  getProvince().then((response) => {
    provinceFormData.value = response.data;
  });
}

function chooseFormProvince(value) {
  form.value.cityId = null;
  form.value.countyId = null;
  querySimulatingEarthquake.value.province = value.name
  cityFormData.value = [];
  areaFormData.value = [];
  getChildArea(value.id).then(response => {
    cityFormData.value = response.data;
  });
}

function chooseFormCity(value) {
  form.value.countyId = null;
  areaFormData.value = [];
  querySimulatingEarthquake.value.city = value.name
  getChildArea(value.id).then(response => {
    areaFormData.value = response.data;
  });
}
function chooseFormDistrict(value) {
  querySimulatingEarthquake.value.district = value.name
}

// 设为当前事件
function handleSet(row) {
  proxy.$modal.loading('正在设置，请稍等...')
  setCurrentEvent(row.xsemId).then(res => {
    getList();
    proxy.$modal.closeLoading();
    proxy.$modal.msgSuccess("设置成功");
    eventStore.changeCurrentEvent({ id: row.xsemId, eventName: row.eventName })
  }).catch((err) => {
    proxy.$modal.closeLoading();
  });
  getListAll(row.xsemId)
}
// 新建
function handleAdd() {
  isNew.value = true
  open.value = true;
  getList1();
  selectRadio.value = '';
  forbidden.value = false;
  selectionData.value = {};
  queryParamsForm.value.magnitude = undefined;
  proxy.resetForm("sjglRef");
}
// 编辑
function handleEdit(row) {
  title.value = '编辑地震事件'
  detail(row.xsemId);
}
// 查看
function detail(id) {
  getDetail({ id: id }).then(res => {
    openAdd.value = true;
    proxy.resetForm("addRef");
    form.value = res.data;
  })
}
// 保存
function save() {
  proxy.$refs["addRef"].validate(valid => {
    if (valid) {
      proxy.$modal.loading('正在保存，请稍等...')
      if (isNew.value) {
        if (title.value == '新建地震事件') {
          saveData({ ...form.value,jscId:selectionData.value.jscId }).then(res => {
            proxy.$modal.msgSuccess("新建成功");
            proxy.$modal.closeLoading()
            openAdd.value = false;
            getList();
          }).catch((err) => {
            proxy.$modal.closeLoading()
            proxy.$modal.msgError(err.data.message);
          })
        } else {
          updateDate({ ...form.value }).then(res => {
            proxy.$modal.msgSuccess("保存成功");
            proxy.$modal.closeLoading()
            openAdd.value = false;
            getList();
          }).catch((err) => {
            proxy.$modal.closeLoading()
          })
        }
      } else {
        convert({ ...form.value, convertedXsemId: m_curRow.xsemId }).then(res => {
          proxy.$modal.closeLoading()
          proxy.$modal.msgSuccess("保存成功");
          openAdd.value = false;
          getList();
        }).catch(()=>{proxy.$modal.closeLoading()})
      }
    }
  })

}
// 下
function lower() {
  title.value = '新建地震事件';
  getName();
}
// 上
function upper() {
  openAdd.value = false;
  // handleAdd();
  open.value = true;
  selectRadio.value = '';
  forbidden.value = false;
  selectionData.value = {};
  queryParamsForm.value.magnitude = undefined;
  proxy.resetForm("sjglRef");
}
// 
function getName() {
  const query = {
    fzTime: selectionData.value.fzTime.replace(/\s*-*:*/g, ""),
    location: selectionData.value.location,
    magnitude: selectionData.value.magnitude,
    occurrenceDate: selectionData.value.occurrenceDate,
    createOrNot:selectionData.value.createOrNot,
  }
  getDataName({ ...query }).then(res => {
    open.value = false;
    openAdd.value = true;
    proxy.resetForm("addRef");
    form.value.eventName = res.data.eventName;
    form.value.eventCode = res.data.eventCode;
    form.value.magnitude = selectionData.value.magnitude;
    form.value.eventTime = selectionData.value.fzTime;
    form.value.epicentralSite = selectionData.value.location;
    form.value.sourceDepth = selectionData.value.depth
    form.value.createUnit = res.data.createUnit;
    form.value.createUserName = res.data.createUserName;
    form.value.createUser = res.data.createUser;
    form.value.createTime = res.data.createTime;
    form.value.seismicCode = selectionData.value.eventId;
    form.value.longitude = selectionData.value.longitude;
    form.value.latitude = selectionData.value.latitude;
    form.value.createOrNot = selectionData.value.createOrNot;
    form.value.province = selectionData.value.province
    form.value.city = selectionData.value.city
    form.value.county = selectionData.value.county
  })
}

function getCurrentRow(row) {
  if (!forbidden.value) {
    forbidden.value = true
  }
  if (selectRadio.value) {
    if (selectRadio.value == row.jscId) {
      selectRadio.value = ''
      forbidden.value = false
      setTimeout(() => {
        forbidden.value = true
      }, 0)
      selectionData.value = {};// 取消勾选就把回传数据清除
      return
    } else {
      forbidden.value = false
      setTimeout(() => {
        forbidden.value = true
      }, 0)
    }
  } else {
    forbidden.value = false
    setTimeout(() => {
      forbidden.value = true
    }, 0)
  }
  selectRadio.value = row.jscId;
  selectionData.value = row;
}

// 转换
function handleTransformation(row) {
  //proxy.$modal.msg("功能暂无");
  isNew.value = false
  m_curRow = row
  open.value = true;
  selectRadio.value = '';
  forbidden.value = false;
  selectionData.value = {};
  queryParamsForm.value.magnitude = undefined;
  proxy.resetForm("sjglRef");
}
// 删除
function handleDelete() {
  proxy.$modal.msg("功能暂无");
}
/** 删除按钮操作 */
// function handleDelete(row) {
//   proxy.$modal
// 			.confirm("是否确认删除信息，请确认是否要删除？", )
// 			.then(function() {
// 				return del(row.xsemId);
// 			})
// 			.then(() => {
// 				getList();
// 				proxy.$modal.msgSuccess("删除成功");
// 			})
// 			.catch(() => {});
// }
// 结束
function handleEnd(row) {
  // proxy.$modal.msg("功能暂无");
  endSeismicEventCheck(row.xsemId).then(res => {
    proxy.$modal.confirm(res.data, ).then(function() {
      return endSeismicEvent(row.xsemId);
    }).then(() => {
      getList();
      proxy.$modal.msgSuccess("结束成功");
    }).catch(() => {

    });
  }).catch(err => {

  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1;
  getList();
}

/** 搜索按钮操作 */
function handleQuery1() {
  queryParamsForm.value.page = 1;
  getList1();
}

/** 重置按钮操作 */
function resetQuery() {
  dataList.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 查询数据列表 */
function getList() {
  loading.value = true;
  getAllList({ ...queryParams.value }).then(response => {
    dataList.value = response.data.rows ? response.data.rows : [];
    total.value = response.data.total;
    loading.value = false;
  }).catch(err=>{loading.value = false});
}

function getList1() {
  loading1.value = true;
  getAllList1({ ...queryParamsForm.value }).then(response => {
    dataList1.value = response.data.rows ? response.data.rows : [];
    total1.value = response.data.total;
    loading1.value = false;
  }).catch(err=>{loading1.value = false});
}
const simulatingEarthquakeBool = ref(false)
function addSimulatingEarthquake() {
  simulatingEarthquakeBool.value = true
  title1.value = '新增模拟地震'
  jscId.value = ''
  querySimulatingEarthquake.value.province = ''
  querySimulatingEarthquake.value.city = ''
  querySimulatingEarthquake.value.district = ''
  querySimulatingEarthquake.value.town = ''
  querySimulatingEarthquake.value.location = ''
  querySimulatingEarthquake.value.eventAbbrevia = ''
  querySimulatingEarthquake.value.longitude = ''
  querySimulatingEarthquake.value.latitude = ''
  querySimulatingEarthquake.value.magnitude = ''
  querySimulatingEarthquake.value.depth = ''
  querySimulatingEarthquake.value.time = ''
}
function saveSimulatingEarthquake() {
  querySimulatingEarthquake.value.occurrenceTime = querySimulatingEarthquake.value.time.split(' ')[1]
  querySimulatingEarthquake.value.occurrenceDate = querySimulatingEarthquake.value.time.split(' ')[0]
   proxy.$refs["simulatingEarthquake"].validate(valid => {
    if (valid != '') {
      if(jscId.value != '') {
        querySimulatingEarthquake.value.jscId = jscId.value
        simEarUpdate({ ...querySimulatingEarthquake.value}).then(res => {
          getList1();
          proxy.$modal.msgSuccess("修改成功");
          simulatingEarthquakeBool.value = false
        }).catch(err => {
          proxy.$modal.msgError(err.data.message);
        })
      }else{
        simEarSave({ ...querySimulatingEarthquake.value}).then(res => {
          getList1();
          proxy.$modal.msgSuccess("保存成功");
          simulatingEarthquakeBool.value = false
        }).catch(err => {
          proxy.$modal.msgError(err.data.message);
        })
      }
    }
  })
}
const jscId = ref('')
const title1 = ref('')
function updateSimulatingEarthquake(value) {
  jscId.value = value.jscId
  title1.value = '修改模拟地震'
  querySimulatingEarthquake.value.province = value.province
  querySimulatingEarthquake.value.city = value.city
  querySimulatingEarthquake.value.district = value.county
  querySimulatingEarthquake.value.town = value.town
  querySimulatingEarthquake.value.location = value.location
  querySimulatingEarthquake.value.eventAbbrevia = value.eventAbbrevia
  querySimulatingEarthquake.value.longitude = value.longitude
  querySimulatingEarthquake.value.latitude = value.latitude
  querySimulatingEarthquake.value.magnitude = value.magnitude
  querySimulatingEarthquake.value.depth = value.depth
  querySimulatingEarthquake.value.time = value.occurrenceDate + ' ' + value.occurrenceTime
  simulatingEarthquakeBool.value = true
}
function deleteSimulatingEarthquake(value) {
  proxy.$modal.confirm("是否确认删除信息，请确认是否要删除？", ).then(function() {
    return simEarDelete(value.jscId);
  }).then(() => {
    getList1();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
    proxy.$modal.msgError(err.data.message);
  });
}
/** 查询数据列表 */
function getListAll(id) {
  if (currentEvent.value) {
      getDetailAll(id).then(res => {
      	if(res.data){
      		
      	}else{
      		formQuery.value.intact1 = "3";
					formQuery.value.minor1="11";
					formQuery.value.moderate1="31";
					formQuery.value.serious1="73";
					formQuery.value.destroy1="91";
					formQuery.value.intact2="2";
					formQuery.value.minor2="11";
					formQuery.value.moderate2="31";
					formQuery.value.serious2="73";
					formQuery.value.destroy2="91";
					formQuery.value.intact3="3";
					formQuery.value.minor3="11";
					formQuery.value.moderate3="28";
					formQuery.value.serious3="71";
					formQuery.value.destroy3="86";
					formQuery.value.intact4="3";
					formQuery.value.minor4="11";
					formQuery.value.moderate4="31";
					formQuery.value.serious4="73";
					formQuery.value.destroy4="91";
          formQuery.value.xsemId=id;
          updateLoss(formQuery.value).then(res => {
            // proxy.$modal.msgSuccess("修改成功");
          })
      	}        
    })
  }
}
getList();
getList1();
getProvinceData();
</script>

<style scoped lang="scss"></style>

